﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace Model
{   
    /// <summary>
    /// RESPONSABILITY: - data bucket
    ///                 - add, remove employees
    ///                 - add, remove projects
    /// </summary>
    
    public class Company
    {   
        public string CompanyCode{get;set;}
        public string CompanyDescription{get;set;}
        private List<Employee> CompanyEmployees;
        private List<Project> projects;
        IDGenerator idGenerator = IDGenerator.Instance;
        public int CompanyId{get;private set;}

        static private List<int> companiesIds{get;set;}

        private int CompanyId_Generator()
        {
            Type type=typeof(Company);
            return idGenerator.RandomIDGenerator(type);
        }

        public Company(string companyCode, string companyDescription)
        {
            this.CompanyCode = companyCode;
            this.CompanyDescription = companyDescription;    
            companiesIds = new List<int>();
            CompanyEmployees = new List<Employee>();
            projects = new List<Project>();
            CompanyId= CompanyId_Generator();
            companiesIds.Add(CompanyId);
        }

        public void AddEmployeeToCompany(Employee employee)
        {
            
          this.CompanyEmployees.Add(employee);
            
        }

        public void RemoveEmployeeFromCompany(Employee employee)
        {
           
           this.CompanyEmployees.Remove(employee);
            
        }

        public IEnumerable<Employee> GetAllEmployees()
        {
            return this.CompanyEmployees;
        }

        public Employee GetEmployeeByCode(string employeeCode)
        {
            Employee employee = CompanyEmployees.FirstOrDefault(e => e.EmployeeCode== employeeCode);
            if (employee != null)
            {
                return employee;
            }
            return null;
        }

        public void AddProjectToCompany(Project project)
        {
            this.projects.Add(project);
        }

        public void RemoveProjectFromCompany(Project project)
        {
            this.projects.Remove(project);
        }

        public IEnumerable<Project> GetAllProjects()
        {
            return this.projects;
        }

        public Project GetProjectByCode(string projectCode)
        {
            Project project = projects.FirstOrDefault(p => p.ProjectCode == projectCode);
            if (project != null)
            {
                return project;
            }
            return null;
        }
    }
}
